package com.travel.dao.impl;

/**
* @Title HotelDao.java
* @Package com.travel.dao
* @Author ChenGuanXi
* @Time 2020年10月28日 上午11:13:08
* @Version 1.0
* @Description: TODO
*/
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.RowSet;

import com.travel.dao.RoomTypeDao;
import com.travel.entity.RoomType;
import com.travel.util.DBUtils;

public class RoomTypeDaoImpl implements RoomTypeDao {
	private DBUtils dbUtil = new DBUtils();

	@Override
	public int insertRoomType(RoomType roomType) {
		String sql = "insert into tab_room_type values(null,?)";
		int i = dbUtil.update(sql, roomType.getRoomTypeName());
		return i;
	}

	@Override
	public int deleteRoomType(int roomTypeId) {
		String sql = "delete from tab_room_type where type_id = ?";
		int i = dbUtil.update(sql, roomTypeId);
		return i;
	}

	@Override
	public int updateRoomtype(int roomTypeId, RoomType roomType) {
		String sql = "update tab_room_type set type_name=? where type_id=?";
		int i = dbUtil.update(sql, roomType.getRoomTypeName(), roomTypeId);
		return i;
	}

	@Override
	public List<RoomType> queryAllRoomTypes() {
		String sql = "select type_id,type_name from tab_room_type";
		RowSet rSet = dbUtil.query(sql);
		List<RoomType> list = new ArrayList<RoomType>();
		try {
			while (rSet.next()) {
				int roomTypeId = rSet.getInt("type_id");
				String roomTypeName = rSet.getString("type_name");
				RoomType roomType = new RoomType(roomTypeId, roomTypeName);
				list.add(roomType);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}
